﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AISFMIOperator
{
    public partial class PatientForm : Form
    {
        private Patient p;

        public PatientForm()
        {
            InitializeComponent();

            citycomboBox5.DataSource = City.GetAllCities();
            citycomboBox5.DisplayMember = "CityName";

            sexcomboBox2.Items.Add("Мужской");
            sexcomboBox2.Items.Add("Женский");

            insurancedataGridView1.AutoGenerateColumns = false;
        }

        private void PatientForm_Load(object sender, EventArgs e)
        {
            
        }

        private void label11_Click(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {            
            AddInsurance ai = new AddInsurance(p);
            ai.ShowDialog();

            insurancedataGridView1.DataSource = null;
            insurancedataGridView1.DataSource = p.Insurances;
            insurancedataGridView1.Columns[0].DataPropertyName = "InsuranceOrderNomer";
            insurancedataGridView1.Columns[1].DataPropertyName = "InsurerCompanyName";
            insurancedataGridView1.Columns[2].DataPropertyName = "OwnerName";
            insurancedataGridView1.Columns[3].DataPropertyName = "EffectiveDateString";
            insurancedataGridView1.Columns[4].DataPropertyName = "TerminationDateString";

        }

        private void button5_Click(object sender, EventArgs e)
        {
            p = new Patient();
            p.PatientID = 0;
            lastnametextBox2.Enabled = true;
            firstnametextBox1.Enabled = true;
            middletextBox3.Enabled = true;
            sexcomboBox2.Enabled = true;
            weighttextBox10.Enabled = true;
            heightcomboBox3.Enabled = true;
            dobdateTimePicker1.Enabled = true;
            citycomboBox5.Enabled = true;
            addinsbutton4.Enabled = true;
            editinsbutton3.Enabled = true;
            deleteinsbutton2.Enabled = true;
            insurancedataGridView1.Enabled = true;
            posttextBox1.Enabled = true;
            phonetextBox8.Enabled = true;
            emailtextBox9.Enabled = true;
            addresstextBox1.Enabled = true;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            Address addr = new Address();
            addr.AddressID = 0;
            addr.Addr = addresstextBox1.Text;
            addr.City = (City)citycomboBox5.SelectedItem;
            addr.PostIndex = int.Parse( posttextBox1.Text.Trim());
            addr.Save();

            p.LastName = lastnametextBox2.Text;
            p.FirstName = firstnametextBox1.Text;
            p.MiddleName = middletextBox3.Text;
            p.Weight = float.Parse(weighttextBox10.Text);
            p.Height = float.Parse(heightcomboBox3.Text);
            p.Sex = sexcomboBox2.Text == "Мужской"?'M':'F';
            p.DateOfBirthday = dobdateTimePicker1.Value;
            p.ContactPhone = phonetextBox8.Text;
            p.Email = emailtextBox9.Text;
            p.Address = addr;

            p.Save();

        }
    }
}
